package com.dk.controller;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class ScheduleTest {

    public static void main(String[] args) throws SchedulerException {

        //1.创建调度器，通过SchedulerFactory
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = stdSchedulerFactory.getScheduler();

        //2.创建JobDetail 用来和MyJob进行绑定(Job执行内容)
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("job","group") //jobDetail的唯一标识
                .build();
        //3.构建Trigger实例，每个5s执行一次
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger","triggerGroup")
                .startNow()//立即生效
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(5)//每个五秒执行一次
                        .repeatForever()).build();//一直执行
        //4.执行
        //使用scheduler将jobDetail和Trigger结合起来
        scheduler.scheduleJob(jobDetail,trigger);
        System.out.println(">>>>>>>>>>>>>>开始打印<<<<<<<<<<<<");
        scheduler.start();
    }
}
